<?php

namespace app\adminapi\controller\system;

use app\adminapi\service\SysFileService;
use app\adminapi\validate\SysFileValidate;
use app\common\controller\BaseAdminController;

class SysFileController extends BaseAdminController
{
    public array $notNeedLogin = [];

    public function list()
    {
        $param = (new SysFileValidate())->get()->goCheck('list');
        $result = (new SysFileService())->list($param);
        return app('json')->successWithData($result);
    }

    /**
     * @title 文件重命名
     * @businessType UPDATE
     */
    public function rename()
    {
        $param = (new SysFileValidate())->put()->goCheck('rename');
        $result = (new SysFileService())->renameSysFile($param);
        return app('json')->successWithData($result);
    }

    public function query()
    {
        $param = (new SysFileValidate())->get()->goCheck('query');
        $result = (new SysFileService())->getSysFile($param['id']);
        return app('json')->successWithData($result);
    }

    /**
     * @title 文件移动
     * @businessType UPDATE
     */
    public function move()
    {
        $ids = request()->param('ids');
        // 注入ids参数到put/body中
        $put = request()->put();
        if ($ids) {
            $put['ids'] = $ids;
            request()->withInput(json_encode($put));
        }
        $param = (new SysFileValidate())->put()->goCheck('move');
        $idArr = explode(',', $param['ids']);
        $result = (new SysFileService())->moveSysFile($idArr, $param);
        return app('json')->successWithData($result);
    }

    /**
     * @title 文件删除
     * @businessType DELETE
     */
    public function delete()
    {
        $param = (new SysFileValidate())->delete()->goCheck('delete');
        $result = (new SysFileService())->deleteSysFile(explode(",", $param['ids']));
        return app('json')->successWithData($result);
    }
}